Imports System.Data.SqlClient

Partial Class productdetail
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents btnsend As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim objdt As New GetData
        Dim objdtCom As New GetData
        Dim productId, strErr As String
        strErr = ""
        productId = Request.QueryString("productId")
        Dim cId As String
        cId = ""
        Dim cName As String
        Dim sId As String
        Dim sName As String
        Dim comId As String
        comId = ""
        Dim comName As String
        comName = ""
        Dim description As String
        description = ""
        Dim detail As String
        detail = ""
        Dim comDetail As String
        comDetail = ""
        If productId <> Nothing And productId <> "" Then
            Dim ps = New PreparedStatement("select * from product_info where product_id = @productId")
            ps.addParameter("productId", productId)

            Dim conn As SqlConnection = objdt.getConn()
            objrd = objdt.dr(ps, strErr, conn, objrd)
            If objrd.HasRows Then
                cName = ""
                sName = ""
                objrd.Read()
                cId = objrd.Item("category_id").ToString
                sId = objrd.Item("sub_category_id").ToString
                comId = objrd.Item("company_id").ToString
                Dim prodesc As String = ""
                If objrd.Item("description").ToString <> Nothing Then
                    prodesc = Replace(objrd.Item("description").ToString, "  ", " &nbsp;")
                    prodesc = Replace(prodesc, vbTab, " &nbsp; &nbsp;")
                    prodesc = Replace(prodesc, vbCrLf, "<br />")
                End If
                detail &= "<div id=""productTitle"">" & objrd.Item("product_name").ToString & "</div>" & _
                            "<div class=""showLine""></div>"
                description &= "<div class=""detailSecTitle"">" & _
                                   "<div class=""relativeTitle"">Product Description</div>" & _
                               "</div>" & _
                        "<div class=""proDescription"">" & _
                            prodesc & _
                         "<br/>" & _
                        "</div>"
                productImgSec.InnerHtml = "<img id=""product-detail"" src=""" & objrd.Item("photo_path").ToString & """ height=""250"" width=""250"" />"

                ps.strSql = "select * from product_photo where product_id = @productId"
                ps.parameters.Clear()
                ps.addParameter("productId", productId)
                objrd = objdt.dr(ps, strErr, conn, objrd)
                Dim ppps As String = ""
                While (objrd.Read())
                    ppps += "<div style=""text-align:center;padding:10px;""><img src=""" & objrd.Item("path").ToString & """/></div>"
                End While
                ps.strSql = "select * from Category where category_id = @cId"
                ps.addParameter("cid", cId)
                objrd = objdt.dr(ps, strErr, conn, objrd)
                If objrd.HasRows Then
                    objrd.Read()
                    cName = objrd.Item("category_name").ToString
                End If
                ps.strSql = "select * from sub_category where sub_category_id = @sId"
                ps.addParameter("sId", sId)
                objrd = objdt.dr(ps, strErr, conn, objrd)
                If objrd.HasRows Then
                    objrd.Read()
                    sName = objrd.Item("sub_category_name").ToString
                End If
                levelPathBar.InnerHtml &= "<a href=""productslist.aspx?cId=" & cId & """ >" & cName & "</a>&nbsp;&gt; " & _
                                        "<b>" & sName & "</b>"
                productInfo.InnerHtml = detail
                detailContent.InnerHtml = description & ppps
            End If
            ps.strSql = "select * from merchant_info where company_id = @comId"
            ps.addParameter("comId", comId)
            objrd = objdt.dr(ps, strErr, conn, objrd)
        If objrd.HasRows Then
            objrd.Read()
            comName = objrd.Item("company_name").ToString
            comDetail &= "<div id=""supplierDetailTitle"">Supplier Details</div>" & _
                        "<div class=""company"">" & _
                            "<a id=""companyName"" href=""company.aspx?cid=" & comId & """>" & comName & "</a>" & _
                            "<div id=""companyLocation"">[" & objrd.Item("city").ToString & objrd.Item("state").ToString & "," & objrd.Item("country").ToString & "]</div>" & _
                        "</div>"
            End If
            objdt.closeConn(conn)
        supplierInfo.InnerHtml = comDetail
        Else
        Response.Redirect("category_default.aspx")
        End If

    End Sub

End Class
